﻿using System;
using System.ComponentModel;

namespace OtherDevice.ComDrive
{
    [Description("光源控制器-信诺诚-SEENO-12311075-24-2T")]
    internal class HY_Light_XNC1 : LightCtrlBase
    {
        public HY_Light_XNC1(string strName) : base(strName)
        {
            controlFrom = new XNCLightCtrl();
        }

        public override int Get(int channel)
        {
            return 0;
        }
        public override bool Set(int channel, int value)
        {
            try
            {
                Byte[] byteArray = new byte[] { 0x55, 0xaa, 0x00, 0x02, 0x01, 0x01, 0xf4, 0x07 };
                // bs[3] = (byte)channel;
                byteArray[4] = (byte)channel;
                
                byteArray[5] = Convert.ToByte(value / 255);
                byteArray[6] = Convert.ToByte(value % 255);

                int sum = 0;
                for (int i = 0; i < 7; i++)
                {
                    sum += byteArray[i];
                }
                byteArray[7] = (byte)(sum ^ 0Xff);
                byte[] byteRe = new byte[] { };
               
                return SendAndReciveData(byteArray, ref byteRe, 500);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show($"光源设置失败{ex}");
                return false;
            }
        }
    }
}
